package com.corpgovernment.common.apollo;

import com.ctrip.corp.obt.generic.utils.JsonUtils;
import com.ctrip.corp.obt.generic.utils.StringUtils;
import com.google.common.collect.Lists;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author ll_zhu
 */
@Component
@Data
public class TrainApollo extends CommonApollo {

    /**
     * 账户绑定密码错误拦截的文案描述
     */
    @Value("${accountPasswordFailDesc:}")
    private String accountPasswordFailDesc;
    /**
     * 允许评论的订单状态
     */
    @Value("${allowCommentAbleOrderStatus:['TA','EP','RP','EA','RA']}")
    private String allowCommentAbleOrderStatus;
    /**
     * 下单可用证件类型
     */
    @Value("${cardTypeList:[1]}")
    private String cardTypeList;
    /**
     * 可选国家码
     */
    @Value("${countryCodeInfo:}")
    private String countryCodeInfo;
    /**
     * 支付描述
     */
    @Value("${payInfoTip:}")
    private String payInfoTip;
    /**
     * 火车票支付时间需要处理的服务商code
     */
    @Value("${preSaleTimeDealSupplierCodes:}")
    private String preSaleTimeDealSupplierCodes;
    /**
     * 超差标预定原因提示语
     */
    @Value("${rcTitle:1、请选择预订不可选坐席的原因:}")
    private String rcTitle;
    /**
     * 计算差旅费用时座位优先级顺序
     */
    @Value("${travelStandardSeatInOrder:221,307,205,303,207,304,209,311,226,314,225,301,302,224,203,201}")
    private String travelStandardSeatInOrder;
    /**
     * 火车票产线名称
     */
    @Value("${trainProductType:train}")
    private String trainProductType;
    /**
     * 火车票查询开关
     */
    @Value("${trainSearchOpen:true}")
    private boolean trainSearchOpen;

    @Value("${isAdd12306Account:true}")
    private boolean isAdd12306Account;
    /**
     * 差标提示语
     */
    @Value("${travelStandardsTips:根据公司差旅政策，该坐席已超过您的差旅标准}")
    private String travelStandardsTips;

    /**
     * 航班查询 获取开始数据（聚合方式）异步获取超时时间
     */
    @Value("${switchValueGetTime:10}")
    private Integer switchValueGetTime;

    /**
     * supplier + param
     * @param supplierCode
     * @return
     */
    public String getSupplierSpecialPostParam(String supplierCode) {
        return getAppProperty(supplierCode.concat("param"), "");
    }
    /**
     * 账户绑定密码错误拦截的文案描述
     */
    public String getAccountPasswordFailDesc(){
        return getAppProperty("accountPasswordFailDesc", null);
    }
    /**
     * 允许评论的订单状态
     */
    public List<String> getAllowCommentAbleOrderStatus() {
        return Optional.ofNullable(getAppProperty("allowCommentAbleOrderStatus", "['TA','EP','RP','EA','RA']"))
                .filter(StringUtils::isNotBlank)
                .map(e -> e.split(","))
                .map(e -> Arrays.stream(e).collect(Collectors.toList()))
                .orElse(Lists.newArrayList());
    }

    @Value("${seatCodeList:}")
    private String seatCodeList;
    /**
     * 下单可用证件类型
     */
    public List<Integer> getCardTypeList() {
            Optional<String> cardTypeList = Optional.ofNullable(getAppProperty("cardTypeList", "[1]"));
            if (cardTypeList.isPresent()){
                return JsonUtils.parseArray(cardTypeList.get(), Integer.class);
            }
            return Lists.newArrayList();
        }


    /**
     * 可选国家码
     */
    public String getCountryCodeInfo(){
        return getAppProperty("countryCodeInfo", null);
    }
    /**
     * 支付描述
     */
    public String getPayInfoTip(){
        return getAppProperty("payInfoTip", null);
    }
    /**
     * 火车票支付时间需要处理的服务商code
     */
    public String getPreSaleTimeDealSupplierCodes(){
        return getAppProperty("preSaleTimeDealSupplierCodes", "");
    }
    /**
     * 超差标预定原因提示语
     */
    public String getRcTitle(){
        return getAppProperty("rcTitle", null);
    }
    /**
     * 计算差旅费用时座位优先级顺序
     */
    public String getTravelStandardSeatInOrder(){
        return getAppProperty("travelStandardSeatInOrder", "221,307,205,303,207,304,209,311,226,314,225,301,302,224,203,201");
    }
    /**
     * 火车票产线名称
     */
    public String getTrainProductType(){
        return getAppProperty("trainProductType", "train");
    }
    /**
     * 火车票查询开关
     */
    public boolean getTrainSearchOpen(){
        return Boolean.valueOf(getAppProperty("trainSearchOpen", "true"));
    }
    /**
     * 是否增加12306账号
     */
    public boolean getIsAdd12306Account(){
        return Boolean.valueOf(getAppProperty("isAdd12306Account", "true"));
    }
    /**
     * 差标提示语
     */
    public String getTravelStandardsTips(){
        return getAppProperty("travelStandardsTips", "根据公司差旅政策，该坐席已超过您的差旅标准");
    }

    public String getTripleDesKey(){
        return getAppProperty("triple_des_key", "77ab70151a0502fe454a5927098615e6");
    }

    public String getEncodeRules(){
        return getAppProperty("encodeRules", "htslhtslhtslhtsl");
    }

	public String getSeatCodeList() {
		return seatCodeList;
	}

    public Integer getSwitchValueGetTime() {
        return Integer.parseInt(getAppProperty("switchValueGetTime", "10"));
    }
}
